<!DOCTYPE html>
<html lang="en">
<head>
<title>在线合模工具</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
html
{
	height: 100%;
}

body
{
    background-color: #ffffff;
    margin: 0px;
    height: 100%;
    color: #555;
    font-family: 'inconsolata';
    font-size: 15px;
    line-height: 18px;
    overflow: hidden;
}

h1
{
    margin-top: 30px;
    margin-bottom: 40px;
    margin-left: 20px;
    font-size: 25px;
    font-weight: normal;
}

h2
{
    font-size: 20px;
    font-weight: normal;
}

a
{
    color: #2194CE;
    text-decoration: none;
}

#panel
{
    position: fixed;
    left: 0px;
    width: 250px;
    height: 100%;
    overflow: auto;
    background: #fafafa;
    filter: alpha(Opacity=80);
    -moz-opacity: 0.5;
    opacity: 0.5;
}

#panel #content
{
    padding: 0px 20px 20px 20px;
}

#panel #content .link
{
    color: #2194CE;
    text-decoration: none;
    cursor: pointer;
    display: block;
}

#panel #content .selected
{
    color: #ff0000;
}

#panel #content .link:hover
{
    text-decoration: underline;
}

#viewer
{
    position: absolute;
    border: 0px;
    left: 0px;
    top: 0px;
    width: 100%;
    height: 100%;
    /* overflow: scroll; */
}

#button
{
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 8px;
    color: #fff;
    background-color: #555;
    opacity: 0.7;
}

#button:hover
{
    cursor: pointer;
    opacity: 1;
}

#modelname
{
    width: 95%;
    padding: 5px;
    font-family: inherit;
    font-size: 15px;
    outline: none;
    border: 1px solid #dedede;
}

#modelname:focus
{
    border: 1px solid #2194CE;
}


#panel li b
{
    font-weight: bold;
}

@media all and ( max-width: 840px )
{

    #panel
    {
        position: absolute;
        left: 0;
        top: 0;
        height: 480px;
        width: 100%;
        right: 0;
        z-index: 10000;
        overflow: hidden;
        border-bottom: 1px solid #dedede;
    }

    #content
    {
        position: absolute;
        left: 0;
        top: 90px;
        right: 0;
        bottom: 0;
        font-size: 17px;
        line-height: 22px;
        overflow: auto;
    }


    #panel.collapsed
    {
        height: 56px;
    }
}
</style>
<link href="./lib/editor/style.css" rel="stylesheet"/>
<link href="./lib/style.css" rel="stylesheet"/>
<link href="./css/layui.css" rel="stylesheet"/>
</head>

<body>
<div id="app"></div>
<div class="top-left" id="tladd">
    <div class="top-left-list">
        <ul>
            <li onclick="LoadModel();"><i class="top-i1"></i>添加模型</li>
            <!-- <li onclick="undo();"><i class="top-i2"></i>回退</li>
            <li onclick="redo();"><i class="top-i3"></i>恢复</li> -->
            <li onclick="EditSave1();"><i class="top-i4"></i>保存位置</li>
            <!-- <li onclick="loadEdit('model/testtag0_testtag1.json');"><i class="top-i5"></i>添加编辑</li> -->
        </ul>
    </div>
    <div class="add-model-div" style="display: none;" id="addmodel">
        <div class="sanjiao"></div>
        <div class="add-model-main">
            <div class="object-name">
                <span>模型名称：</span>
                <!-- <input type="text" name="" class="object-name-input" id="txtMdlName"> -->
                <select id="txtMdlName">
                    <option value="">---请选择---</option>
                    <option value="https://model.richtechcn.com/jianzhu/jianzhuList.json">jianzhu</option>
                    <option value="https://model.richtechcn.com/kongyazhan/kongyazhanList.json">kongyazhan</option>
                </select>
            </div>
            <div class="mode-title">
                    模型信息
            </div>
            <div class="mode-path">
                <ul>
                    <li>
                        <label>位置信息：</label><span>x</span><input type="text" name="" class="input-x" id="txtpostionx" value="0"><span>y</span><input type="text" name="" class="input-x" id="txtpostiony" value="0"><span>z</span><input type="text" name="" class="input-x" id="txtpostionz" value="0"><i class="mode-path-i" onclick="getpostion();"></i><span>拾取坐标</span>
                    </li>
                    <li>
                        <label>模型旋转：</label><span>x</span><input type="text" name="" class="input-x" id="txtrotatex" value="0"><span>y</span><input type="text" name="" class="input-x" id="txtrotatey" value="0"><span>z</span><input type="text" name="" class="input-x" id="txtrotatez" value="0">
                    </li>
                    <li>
                        <label>缩放倍速：</label><input type="text" name="" class="object-name-input" id="txtscale" value="1.0">
                    </li>
                </ul>
            </div>
            <div class="model-btn">
                <button type="button" onclick="colsePostion();">取消</button>
                <button type="button" onclick="addmodelfun();">确定</button>
            </div>
        </div>
    </div>	
    </div>
   
    <div id="viewer"></div>
    <div class="Panel" id="toolbar">
        <div class="Panel">
            <button class="Button selected" style="padding: 4px 28px;" onclick="changeMode('translate',this);">位置</button>
            <button class="Button" style="padding: 4px 28px;" onclick="changeMode('rotate',this);">旋转</button>
            <button class="Button" style="padding: 4px 28px;" onclick="changeMode('scale',this);">缩放</button>
        </div>
    </div>
    <div class="right-model-div" id="sidebar">
        <div class="right-model-list">
            <div class="model-list-title">模型列表</div>
            <ul class="model-list-conter" id="outliner"></ul>
        </div>
        <div class="right-model-list m-t30">
            <div class="model-list-title">OBJECT</div>
            <div class="right-model-type">
                <ul id="ViewPanel">
                    <li>
                        <label>类型：</label><p id="li_type"></p>
                    </li>
                    <li>
                        <label>名字：</label><input type="text" id="li_name" class="right-model-input" style="width: 238px;">
                    </li>
                    <li>
                        <label>显示：</label>
                        <div class="on-off">
                            <input type="checkbox" name="sex" id="male" class="chooseBtn" />
                            <label for="male" class="choose-label"></label>
                        </div>
                    </li>
                    <li>
                        <div class="ldw">
                            <label>位置：</label>
                        </div>
                        <div class="ldw">
                            <div class="xz-div">
                                <span>x</span><i id="ipostion_xjia">+</i><input type="text" id="li_postionx" class="xz-j"><i id="ipostion_xjian">-</i>
                            </div>
                            <div class="xz-div">
                                <span>y</span><i id="ipostion_yjia">+</i><input type="text" id="li_postiony" class="xz-j"><i id="ipostion_yjian">-</i>
                            </div>
                            <div class="xz-div">
                                <span>z</span><i id="ipostion_zjia">+</i><input type="text" id="li_postionz" class="xz-j"><i id="ipostion_zjian">-</i>
                            </div>
                        </div>
                    </li>
                    <li>
                        <label>旋转：</label>

                        <div class="xz-div">
                            <span>x</span><i id="irotate_xjia">+</i><input type="text" id="li_rotatex" class="xz-j"><i id="irotate_xjian">-</i>
                        </div>
                        <div class="xz-div">
                            <span>y</span><i id="irotate_yjia">+</i><input type="text" id="li_rotatey" class="xz-j"><i id="irotate_yjian">-</i>
                        </div>
                        <div class="xz-div">
                            <span>z</span><i id="irotate_zjia">+</i><input type="text" id="li_rotatez" class="xz-j"><i id="irotate_zjian">-</i>
                        </div>
                    </li>
                    <li>
                        <label>缩放：</label>
                        <div class="on-off">
                            <input type="checkbox" name="sex" id="li_scalelock" class="chooseBtn" />
                            <label for="li_scalelock" class="choose-label"></label>
                        </div>
                        <div class="xz-div">
                            <span>x</span><i id="iscale_xjia">+</i><input type="text" id="li_scalex" class="xz-j"><i id="iscale_xjian">-</i>
                        </div>
                        <div class="xz-div">
                            <span>y</span><i id="iscale_yjia">+</i><input type="text" id="li_scaley" class="xz-j"><i id="iscale_yjian">-</i>
                        </div>
                        <div class="xz-div">
                            <span>z</span><i id="iscale_zjia">+</i><input type="text" id="li_scalez" class="xz-j"><i id="iscale_zjian">-</i>
                        </div>
                    </li>
                    <li>
                        <label>属性：</label>
                        <div class="xz-div">
                            <span>长</span><i id="property_length">+</i><input type="text" id="li_property_length" class="xz-j"><i id="property_length_xjian">-</i>
                        </div>
                        <div class="xz-div">
                            <span>宽</span><i id="property_width">+</i><input type="text" id="li_property_width" class="xz-j"><i id="property_length_yjian">-</i>
                        </div>
                        <div class="xz-div">
                            <span>高</span><i id="property_height">+</i><input type="text" id="li_property_height" class="xz-j"><i id="property_length_zjian">-</i>
                        </div>
                    </li>
                </ul>
            </div>
        </div>
    </div>
    <!-- 模型弹出层 -->
    <div class="role-div-add" id="mold_member_div">
        <ul class="role-div-add-ul layui-form">
            <li>
                <label>模型名称：</label>
                <div class="layui-input-block">
                    <input type="text" name="inputName" autocomplete="off" class="layui-input" id="inputName">
                    <input type="hidden" name="add_namestr" id="add_namestr">
                    <input type="hidden" name="add_output" id="add_output">
                </div>
            </li>
            <li>
                <button class="cancel-btn m-l10" onclick="subAddData();">确定</button>
                <button class="cancel-btn m-l10" id="close-btn">取消</button>
            </li>
        </ul>
    </div>
    <!-- 模型弹出层 -->
<script src="./lib/jquery-3.3.1.min.js"></script>
<script src="./layui.js"></script>
<script src="./3dEngine.js"></script>
<script>
layui.use('layer', function(){
    var layer = layui.layer;
});
EngineInit("viewer");
var nameArray = ['1RV'];

var modelArray = [];
var currentIndex = 0;

SetClickMode(0);
//监听加载的事件
function OnLoadModelEnd(tag) {
    var txtMdlName = $("#txtMdlName").val();
    var txtMdlText = $("#txtMdlName").find("option:selected").text();
    var options = "";
    options += '<li class="option" id="opt_' + txtMdlText + '" value="scene_' + tag + '"><a href="javascript:;">' + txtMdlText + '</a></li>';

    $("#outliner").append(options);

    $("#outliner .option").click(function () {
        if (GetClickMode() == 0) {
            $("#outliner .option").removeClass("active");
            $(this).addClass("active");
            selectEditModel($(this).attr("value"));
        }
    });
    /* alert('load finish!'); */
    layer.msg("加载完成！", {icon:1});
    colsePostion();

    currentIndex++;

    if ($("#txtpostionx").val() * 1 != 0 && $("#txtpostiony").val() * 1 != 0 && $("#txtpostionz").val() * 1 != 0) {
        JumpToPostion('scene_' + tag, $("#txtpostionx").val() * 1, $("#txtpostiony").val() * 1, $("#txtpostionz").val() * 1);
    }
};

var lastid = '';
var cameraPos = '';
var clickpos = '';

//监听点击的坐标
function OnClickPosition(position) {
    var ss = position.toString().split(",");
    $("#txtpostionx").val(ss[6]);
    $("#txtpostiony").val(ss[7]);
    $("#txtpostionz").val(ss[8]);
}
   
function LoadModel() {
    $("#addmodel").toggle();
}
   
function addmodelfun() {
    var txtMdlName = $("#txtMdlName").val();
	if(txtMdlName!=""){
        AddModel($("#txtMdlName").val(), 'testtag' + currentIndex);
    	AddModel(txtMdlName, 'testtag' + currentIndex);
    }else{
		layer.msg("请选择模型文件！", {icon:1});
  }	
   AddModel($("#txtMdlName").val(), 'testtag' + currentIndex);
}

function getpostion() {
    SetClickMode(1);
}

function colsePostion() {
    SetClickMode(0);
    $("#addmodel").hide();
}

//上传并插入文件
function EditSave1() {
    var output = GLE_HTY.toJSON();
    output = JSON.stringify(output);
    output = output.replace(/[\n\t]+([\d\.e\-\[\]]+)/g, "$1");
    var namestr = "";
    $("#outliner li").each(function(i) {
        namestr += $(this)[0].innerText + "_"
    });
    namestr = trimstr(namestr, "_");
    //funDownload(output, namestr + ".json")
    
    //判断加载模型的个数，不适用于模型中本身就有'_'
    if(namestr.indexOf('_')==-1){
    	layer.msg("请上传另一个需要合并的模型！", {icon:1});
    	return false;
    }
    var index=layer.open({
        type: 1,
        title:'添加模型名称',
        skin: 'layui-layer-demo', //样式类名
        closeBtn: 1, //不显示关闭按钮
        area: ['320px', '200px'], //宽高
        anim: 2,
        shadeClose: true, //开启遮罩关闭
        content: $('#mold_member_div')
    });
    $('#close-btn').click(function(){
        layer.close(index);
    });
    
    // alert("output==="+output);
    //暂存隐藏域
    $("#add_namestr").val(namestr);
    $("#add_output").val(output);
}

//保存
function subAddData(){
	//获取输入的模型名称
	var inputName = $("#inputName").val();
    var add_namestr = $("#add_namestr").val();
	var add_output = $("#add_output").val().toString();
	
	//模型名称
	if($.trim(inputName) == ""){
		layer.msg("请输入新生成的模型名称！", { icon:0});
		return false;
	}
	
	//保存提交
    $.ajax({
        type: 'Post',
        dataType: 'json',
        contentType: 'application/json;charset=utf-8',
        url: 'https://api.richtechcn.com/api/DieModel/AddDieData',
	    data: JSON.stringify({
            BeforeMName:add_namestr,
            ModelUrl:add_output,
            LaterMName:inputName
        }),
	    success: function (data) {
	    	if(data.code == 0){
                layer.closeAll();
                layer.msg("模型合并完成！", {icon:1,time:1000});
	    	} else {
	    		layer.msg(data.msg, {icon:2});
	    	}
	    }
	});
}

</script>
</body>
</html>
